import qqMap from '../../../utils/qqmap'
import Dialog from '../../../miniprogram_npm/@vant/weapp/dialog/dialog';
// map.js
Page({
  data: {
    latitude: 40.060539,
    longitude: 116.343847,
    list: [],
    markers: [{
      id: 0,
      "latitude": 39.907423,
      "longitude": 116.409091,
      "title": "长安大厦",
      "iconPath": "../../../img/1.jpg",
      "width": 20,
      "height": 20
    }, {
      id: 1,
      "latitude": '',
      "longitude": '',
      "title": "长安大厦",
      "iconPath": "../../../img/2.jpg",
      "width": 20,
      "height": 20
    }],
    polyline: [{
      "points": [{
        "latitude": 39.907423,
        "longitude": 116.409091
      }, {
        "latitude": 39.90469,
        "longitude": 116.40717,
      }],
      "width": 2,
      "arrowLine": true,
      "color": "#FF0000DD"
    }]
  },
  onLoad({ id }) {
    this.getList(id)
  },
  async getLocation() {
    await wx.getLocation({
      type: 'gcJ02',
      success: (res) => {
        // console.log('位置', res);
        this.setData({
          "latitude": res.latitude,
          "longitude": res.longitude,
          "markers[1].latitude": res.latitude,
          "markers[1].longitude": res.longitude,
        })
      }
    })

    //地图map中的SDK。
    qqMap.direction({
      mode: 'driving',
      success: (res) => {
        console.log(res);
        // console.log('位置', marks);
        this.setData({
          "polyline.points": [{
            "latitude": 39.907423,
            "longitude": 116.409091
          }, {
            "latitude": 39.90469,
            "longitude": 116.40717,
          }],
          "polyline.width": 2,
          "polyline.arrowLine": true,
          "polyline.color": "#FF0000DD"
        })
        console.log('看位置信息', this.data.polyline);
      }
    })

  },

  async getList(id) {
    const { data } = await wx.http.get('/repair/' + id)
    console.log(data);
    this.setData({
      list: data
    })
    if (data.status === 2) {
      this.getLocation()
    }
  },
  //点击包修
  edit(e) {
    // console.log(e);
    wx.navigateTo({
      url: `/repair_pkg/pages/form/index?id=${e.mark.id}`,
    })
  },
  //取消保修
  test() {
    Dialog.confirm({
      title: '提示',
      message: '确认取消'
    }).then(() => {
      wx.navigateTo({
        url: `/repair_pkg/pages/list/index`,
      })
    }).catch((error) => {
      console.log(error);

    })
  }
})
